<?php

	class Service {
		public $apiUserInnerUrl = '';

		protected $apiKey = '';

		protected $dispatch = "dispatchWeb/index";
		protected $error = '';
		protected $message = '';

		public function getError() {
			return $this->error;
		}

		public function getMsg() {
			return $this->message;
		}

		protected function httpGet($params, $url = null){
			if (!empty($url)) {
				$this->apiUserInnerUrl = $url;
			}

			$url = $this->apiUserInnerUrl. "?".http_build_query($params);

			$res = HttpUtil::curlGet($url, 5, "");

			$res = json_decode($res, true);

			$this->error = '操作失败';
			if (!$res[0]['code']){
				return false;
			}

			if(empty($res) || !isset($res[0]['code'])){
				$this->error = isset($res[0]['msg'])?$res[0]['msg']:$res[0]['message'];
				return false;
			}

			if ($res[0]['code'] != Status::SUCCESS){
				$this->error = isset($res[0]['msg'])?$res[0]['msg']:$res[0]['message'];
				return false;
			}
			$this->message = isset($res[0]['msg'])?$res[0]['msg']:$res[0]['message'];
			return empty($res[0]['data'])?true:$res[0]['data'];
		}

		/**
		 * [buildQuery 构建查询参数]
		 * @param  [type] $params [description]
		 * @return [type]         [description]
		 */
		protected function buildQuery($jsonparams) {
			$params['channelid'] = isset($_REQUEST['channelid'])?intval($_REQUEST['channelid']):

			$params['sign'] = md5(CommonUtil::encodePassword(self::$btgoappKey).$params['appid'].$params['channelid'].$params['params']);
			return $params;
		}
	}